package internal

import (
	"gogogo-server/engine/module"
	"gogogo-server/logicserver/gamelogic/unitrole"
	"gogogo-server/logicserver/gamelogic/unitroom"
)

var LocalModule *LetGoGame

type LetGoGame struct {
	*module.LGLogic
	mgrList []IManager
}

func (lg *LetGoGame) OnInit() error {
	LocalModule = lg
	lg.LGLogic = module.NewLGLogic(nil)
	lg.registerHandlers()
	lg.registerManagers()
	return nil
}

func (lg *LetGoGame) registerManagers() {
	lg.mgrList = make([]IManager, 0)
	lg.mgrList = append(lg.mgrList, unitroom.RoomInstance())
	lg.mgrList = append(lg.mgrList, unitrole.RoleInstance())
	for _, m := range lg.mgrList {
		m.OnInit()
	}
}

func (lg *LetGoGame) AfterInit() error { return nil }

func (lg *LetGoGame) OnDestroy() {
	for _, m := range lg.mgrList {
		m.OnDestroy()
	}
}
